<!--病史管理-->
<template>
<h1>病史管理</h1>
  <div style="background-color: #fff;padding: 10px;margin: 5px auto;width: 85%;align-items: center;display: flex;justify-content: center;">
    <span style="line-height: 50px;font-size: 30px;color: lightseagreen">病史管理</span>
  </div>
  <!--  病史搜索卡片-->
  <el-card style="margin: 5px auto;height: 70px;width: 88%">
    <el-form :inline="true">
      <el-form-item label="患者名称">
        <el-input placeholder="请输入" style="width:220px;" v-model="searchSicknessForm.patientName"></el-input>
      </el-form-item>
      <el-form-item label="医生名称">
        <el-input placeholder="请输入" style="width:220px;" v-model="searchSicknessForm.physician"></el-input>
      </el-form-item>
      <el-form-item label="就诊时间">
        <el-date-picker type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" v-model="searchSicknessForm.treatTime"/>
      </el-form-item>
      <el-form-item label="住院状态状态">
        <el-select placeholder="请选择" style="width:220px;" v-model="searchSicknessForm.inpatientStatus">
          <el-option value="1" label="住院" ></el-option>
          <el-option value="0" label="未住院" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetSearch">重置</el-button>
        <el-button type="success" @click="loadSickness" >搜索</el-button>
      </el-form-item>
    </el-form>
  </el-card>

  <!--    病史列表-->
  <el-card style="margin: 1px auto;width: 88%;overflow-y:auto;">
    <div style="margin:2px 0px 40px 10px;">
      病史列表
    </div>
    <el-table  :data="sicknessArr">
      <el-table-column type="index" label="编号" width="80" align="center"/>
      <el-table-column prop="patientName" label="患者名称" align="center"/>
      <el-table-column prop="illness" label="就诊病情" align="center"/>
      <el-table-column prop="physician" label="确诊人" align="center" />
      <el-table-column prop="treatTime" label="就诊时间" align="center"/>
      <el-table-column label="住院状态" align="center" >
        <template #default="scope">
          <el-switch active-value="1" inactive-value="0"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small"  >详情与编辑</el-button>
          <el-button link type="primary" size="small" >删除</el-button>
        </template>
      </el-table-column>
    </el-table>


    <div style="margin:30px;float: right;">
      <!--layout="total(总数), sizes(每页总数), prev(上一页), pager(当前页), next(下一页), jumper(跳转页)"
       :pager-count="4" 表示显示4个页码
       :page-sizes="[5, 10, 15, 20]" 表示一共有几个"每页显示多少条"选项
       current-page当前页码 page-size当前页码的条数 total总条数 这三个变量需要和实际数据双向绑定
       :total="400" 表示总条数，需要双向绑定
       @size-change="handleSizeChange" 表示每页显示多少条改变时触发的事件
       @current-change="handleCurrentChange" 表示当前页码改变时触发的事件 -->
      <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[5, 10, 15, 20]"
          v-model:current-page="currentPage"
          v-model:page-size="currentSize"
          v-model:total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
  </el-card>

  <!--      保存管理员项弹窗-->
  <el-dialog :title="dialogTitle" v-model="dialogVisible" style="width:1000px;padding:40px;"
             :before-close="handleClose">
    <el-form label-width="80px" label-position="top">
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item  label="送修人">
            <el-input  :placeholder="saveRepairFrom.username"
                       :disabled="user.id!=null"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  label="维修车辆">
            <el-select   placeholder="请选择车牌号" v-model="saveRepairFrom.vehicleId" >
              <el-option  v-for="item in vehicleArr"
                          :label="item.license" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item  label="维修项目">
            <el-select   placeholder="请选择" v-model="saveRepairFrom.item">
              <el-option  v-for="item in repairItemsArr"
                          :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  label="维修地点">
            <el-select   placeholder="请选择" v-model="saveRepairFrom.addr" >
              <el-option  v-for="item in repairLocationArr"
                          :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item  label="维修材料">
            <el-select placeholder="请选择" v-model="saveRepairFrom.material">
              <el-option  v-for="item in repairMaterialsArr"
                          :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item   label="维修费用" >
            <el-input v-model="saveRepairFrom.fee" placeholder="请输入"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="维修时间">
            <el-date-picker v-model="saveRepairFrom.repairTime" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="维修状态">
            <el-radio-group v-model="saveRepairFrom.status">
              <el-radio border label="维修中" value="1" style="margin: 0"></el-radio>
              <el-radio border label="已完成" value="0"></el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button>取消</el-button>
      <el-button type="primary">保存</el-button>
    </template>
  </el-dialog>

</template>
<script setup>


//定义变量保存分页器的当前页数
import {onMounted, ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";

const currentPage = ref(1);
//定义变量保存分页器的每页显示多少条
const currentSize = ref(5);
//定义变量保存数据总条目数
const total = ref(100);
//修改每页显示多少条，触发此函数
const handleSizeChange = (val) => {
  console.log('每页展示' + val + '条数据');
  loadSickness();
}
//修改当前页码，触发此函数
const handleCurrentChange = (val) => {
  console.log('当前的页数为：' + val);
  loadSickness();
}

// 定义对象保存搜索病史的条件
const searchSicknessForm = ref({
  patientName:'',
  physician:'',
  treatTime:'',
  inpatientStatus:''
});
// 定义数组保存响应回的病史数据
const sicknessArr = ref([]);

// 定义加载数据的方法
const loadSickness = ()=>{
  searchSicknessForm.value.pageSize = currentSize.value
  searchSicknessForm.value.pageNum = currentPage.value
  let data = qs.stringify(searchSicknessForm.value)
  axios.get(BASE_URL + '/v1/sickness/select?' + data)
      .then((response)=>{
        if (response.data.code == 2000){
          sicknessArr.value = response.data.data.list;
          total.value = response.data.data.total;
        }else {
          ElMessage.error(response.data.msg);
        }
      })
}

// 定义方法重置搜索
const resetSearch = ()=>{
  searchSicknessForm.value = {};
  loadSickness();
}
onMounted(()=>{
  loadSickness();
})


//定义变量保存弹窗的标题
const dialogTitle = ref('修改病史')
// 定义变量控制弹窗是否可见
const dialogVisible = ref(false)

// 定义取消弹窗的方法
const handleClose = ()=>{
  if (confirm('是否要关闭本弹窗?')) {
    dialogVisible.value = false;
  }
}




</script>


<style scoped>

</style>